<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>凉山州高中考志愿填报</title>
<link rel="stylesheet" href="/css/newStyle.css"
	th:href="@{/css/newStyle.css}">
<!-- th:href="@{/css/newStyle.css}" -->
<link href="/css/bootstrap-editable.css" rel="stylesheet"
	th:href="@{/css/bootstrap-editable.css}" />
</head>
<body>
	<div class="mainBox" th:object="${wishOne}">
		<div class="mainBox_inner">
			<h1>凉山州高中阶段招生</h1>
			<div class="tableOutBox">
				<h2>艺体特长审核系统（高中学校端）</h2>
				<div class="tableSearch clearfix">
					<form action="" method="post" id="form1">
						<div class="fl">
							<div class="fl searchOut">
								<input id="param_bmh" type="hidden" name="bmh" value="">
								<input type="text" placeholder="输入学生报名号" class="searchtext">
								<button class="searchbtn"></button>
							</div>
						</div>
					</form>
					<div class="fr rightbox">
					<input type="button" class="btn btn-primary"  onclick="javascript:history.go(-1);" value="返回上级">
						<button id="shenghe" class="shenghe schoolshenghe">审核</button>
						<button class="goshenghe schoolgoshenghe">清除审核</button>
						<!-- <button class="insertchengji">录入考试成绩</button>  -->
					</div>
				</div>
				<div class="toolsbar"></div>
				<div class="tablebox">
					<table id="shenhetable" class="tablebox" border="1" cellpadding="0"
						cellspacing="0" align="left">
					</table>
					<div class="clearfix exportOutbox">
						<div class="fr">
							<!--  <button class="tese">特色项目考生汇总表</button>-->
							<!-- <button class="yiti">艺体特长考生汇总表</button>-->
							<button class="printTablr" onclick="showPdf()">打印考生资格审查表</button>
							<!-- <button class="exportTable">导出通过审核总表</button> -->
						</div>
					</div>
					<!-- <div>提示：如果审批错误，双击错误的哪一行信息，点击清除审核，即可重新审核。</div>  -->
				</div>
			</div>
		</div>
	</div>
</body>
<script src="js/jquery-3.2.1.min.js"></script>
<script src="js/gVerify.js"></script>
<script src="js/commen.js"></script>
<link href="css/bootstrap.css" rel="stylesheet" />
<script src="js/bootstrap.js"></script>
<script src="js/bootstrap-table.js"></script>
<script src="js/bootstrap-editable.min.js"></script>
<script src="js/bootstrap-table-editable.js"></script>
<link href="css/bootstrap-table.css" rel="stylesheet" />
<script src="js/bootstrap-table-zh-CN.js"></script>
<script type="text/javascript" src="js/tableExport.js"></script>
<script type="text/javascript" src="js/base64.js"></script>
<script type="text/javascript" src="js/bootstrap-table-export.min.js"></script>
<script th:inline="javascript">
//var st=[[${students}]];


var curRow={};
$(function () {
    //1.初始化Table
    var arr;
    var oTable = new TableInit();
    oTable.Init();
})

var TableInit = function () {
    var oTableInit = new Object();
    oTableInit.Destory = function () {
        $('#shenhetable').bootstrapTable('destroy');
    };
    oTableInit.Init = function () {
        $("#shenhetable").bootstrapTable({
            url: "showHighSchoolYt",         //请求后台的URL（*）
            contentType: "application/x-www-form-urlencoded",
            method: 'post',                      //请求方式（*）
            toolbar: '#toolbar',                //工具按钮用哪个容器
            striped: true,                      //是否显示行间隔色
/*             dataField:'studentstr', */
            cache: true,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
            pagination: true,                   //是否显示分页（*）
            silent: true,
            sortable: true,                     //是否启用排序
            sortOrder: "asc",                   //排序方式
            queryParams: oTableInit.queryParams,//传递参数（*）
            queryParamsType: "undefined",
            sidePagination: "client",           //分页方式：client客户端分页，server服务端分页（*）
            pageNumber: 1,                       //初始化加载第一页，默认第一页
            pageSize: 10,                       //每页的记录行数（*）
            pageList: [10, 25, 50, 100],        //可供选择的每页的行数（*）
            search: false,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
            strictSearch: false,
            showColumns: true,                  //是否显示所有的列
            showRefresh: true,                  //是否显示刷新按钮
            minimumCountColumns: 2,             //最少允许的列数
            clickToSelect: true,                //是否启用点击选中行
            /* height: 500, */                        //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
            uniqueId: "ID",                     //每一行的唯一标识，一般为主键列
            showToggle: false,                    //是否显示详细视图和列表视图的切换按钮
            cardView: false,                    //是否显示详细视图
            detailView: false,                   //是否显示父子表
            showExport: true, 
            exportTypes:['excel'],
            exportDataType: 'all',
            exportOptions:{  
                ignoreColumn: [0],  //忽略某一列的索引  
                fileName: '艺体特长表',  //文件名称设置  
                worksheetName: 'sheet1',  //表格工作区名称  
                tableName: '艺体特长表',  
            }, 
            columns: [{
                field: 'chose',
                checkbox: true
            },
            {field: 'id',title: 'ID',align: 'center'},
          {field: 'xm',	title: '姓名', align: 'center'},
            {
                field: 'bmh',
                title: '报名号'
                , align: 'center'
            },
            {
                field: 'sfzh',
                title: '身份证号'
                , align: 'center'
            },
            {
                field: 'gzxxmc',
                title: '报考学校'
                , align: 'center'
            },
        /*     {
                field: 'tszymc',
                title: '特色项目'
                , align: 'center'
            },
            {
                field: 'tskhcj',
                title: '特色项目成绩',
	            editable: {
	                type: 'text',
	                title: '成绩',
	                validate: function (v) {
	                    if (!v) return '成绩不能为空';
	
	                }
	            },
                align: 'center',
                //formatter: function (value, row, index) {
                //    //return "<a href=\"#\" name=\"Tskhcj\" data-type=\"text\" data-pk=\""+row.Id+"\" data-title=\"成绩\">" + value + "</a>";
                //    return "<a href=\"#\" name=\"Tskhcj\" data-type=\"text\" data-pk=\"+row.Id+\" data-title=\"成绩\">" + "1" + "</a>";
                //},        // <a href="http://www.w3school.com.cn">W3School</a>
                

            } */
            
            {
                field: 'ytzymc',
                title: '艺体特长'
                , align: 'center'
            },
            {
                field: 'ytkhcj',
                title: '艺体特长成绩'
                ,editable: {
	                type: 'text',
	                title: '成绩',
	                validate: function (v) {

	                   if (!v) return '成绩不能为空';
	                   
	                    var re = /^[0-9]+.?[0-9]*$/;   //判断字符串是否为数字     //判断正整数 /^[1-9]+[0-9]*]*$/
	                    re = /^[0-9]+(.[0-9]+)?$/;
	                    if (!re.test(v))
	                   {
	                       alert("请输入数字(例:60.02)");
	                       //input.rate.focus();
	                       return false;
	                    }
            
	
	                }
	            }
                , align: 'center'
            } 
            ,
            {
                field: 'gzshzt',
                title: '学校审核'
    	        ,editable: {
   	                type: 'select',
   	                source: [{ value: 0, text: "未审核" }, { value: 1, text: "审核通过" }, {value:2,text:"审核未通过"}],
   	                emptytext: "未审核",       //空值的默认文本
   	                title: '审核状态',
   	                validate: function (v) {
   	                    if (!v) return '审核状态不能为空';
   	
   	                }
    	        }
                , align: 'center'
                //	,formatter:function(value,row,index){
                //    	var a="";
                //        if (value==null || value == "0"){a="未通过";};
                //        if (value=="1"){a="审核通过";};
                //        return a;
                //    }
            }],
            onEditableSave: function (field, row, oldValue, $el) {
                $.ajax({
                    type: "post",
                    url: "/highschool/doSaveScoreYt",
                    data: row,
                    dataType: 'JSON',
                    async:true,
                    success: function (data, status) {
                        if (data.code == "ok") {
                            alert('更新成功');
                            $("#shenhetable").bootstrapTable('refresh');
                        }else{
                        	alert(data.message);
                        	$("#shenhetable").bootstrapTable('refresh');
                        }                    
                    },
                    error: function (error) {
                        alert('编辑失败');
                        //alert(error);
                    },
                    complete: function () {

                    }

                });
            },
            onClickRow: function (row, $element) {
                curRow = row;
            },
            onLoadSuccess: function (aa, bb, cc) {
                $("#shenhetable a").editable({
                    url: function (params) {
                        var sName = $(this).attr("name");
                        curRow[sName] = params.value;
                        $.ajax({
                            type: 'POST',
                            url: "",
                            data: curRow,
                            dataType: 'JSON',
                            success: function (data, textStatus, jqXHR) {
                                alert('保存成功！');
                            },
                            error: function () { alert("error");}
                        });
                    },
                    type: 'text'
                });
            },
             //data:st, 
        });
    };
    oTableInit.queryParams = function (params) {
        var param = {
            bmh: $(".searchtext").val(),
            pageSize: params.pageSize,   //页面大小
            pageIndex: params.pageNumber,  //页码
        };
        return param;
    };
    return oTableInit;
};

$(".searchbtn").click(function() {
    var param = {
      bmh: $("#searchtext").val(),
      pageSize:1,   //页面大小
      pageIndex: 10,  //页码
  };
  $.ajax({
  	url:"showHighSchoolYt",
  	type:"post",
  	data:param,
      success:function(data){}
  })
$('#shenhetable').bootstrapTable('refresh');
  $(".searchtext").val("");    
return false;
})


	//导出通过审核总表
	$(".exportTable").on('click', function() {
	    //导出
	    $("#shenhetable").tableExport({type:"excel",escape:"false"},'艺体特长考生汇总表');
	    alert("导出完成");
	});
	
	
	function test(){
	     
	      var  iframe = document.getElementById("printIframe");
	      iframe.type="application/pdf";
	      document.getElementById("printIframe").src = 'thymeleaf_3.0.5.pdf';
	 
	      if (iframe.attachEvent){ 
	            iframe.attachEvent("onload", function(){ 
	              // alert("Local iframe is now loaded."); 
	              document.getElementById("printIframe").contentWindow.print();
	        }); 
	        } else { 
	        iframe.onload = function(){ 
	             // alert("Local iframe is now loaded."); 
	             document.getElementById("printIframe").contentWindow.print();
	        }; 
	     } 
	       
	}
	
	
	$(document).ready(function(){
		var iframe = document.createElement("printIframe"); 
		if (iframe.attachEvent){
			iframe.attachEvent("onload", function(){
				alert("Local iframe is now loaded.");
			});
		} else { 
			$("#printIframe").load(function(){
	    	//等待iframe加载完成后再执行doPrint.每次iframe设置src之后都会重新执行这部分代码。
	        //doPrint();
        	});
		}
		document.body.appendChild(iframe);
		//doPrint();
	});

	//点击打印按钮，触发事件】
	function printPDF(){
	    var src = $("#printIframe").attr("src");
	    if(!src){//当src为空，即第一次加载时才赋值，如果是需要动态生成的话，那么条件要稍稍变化一下
	        $("#printIframe").attr("src","testV1.0.pdf");//暂时静态PDF文件
	    }
	    doPrint();
	}
	function doPrint(){
		var pp = $("#printIframe")[0];
	    $("#printIframe")[0].contentWindow.print(); 
	    //jQuery("#printIframe").get(0).contentWindow.print();
	}

	function print2() {
	    var curWwwPath=window.document.location.href;
	    var pathName=window.document.location.pathname;
	    var pos=curWwwPath.indexOf(pathName);
	    var localhostPath=curWwwPath.substring(0,pos);
	    window.open("/preview?fileName=testV1.0.pdf");

	};

	function showPdf(){
		var row= $('#shenhetable').bootstrapTable('getSelections');
		if(row.length<1)
			{
			alert("未选择学生");
			return false ;
			}
		//执行审核请求
		$.ajax({
			type : 'POST',
			url : '/highschool/exportpdfYt',
			data : row[0],
			dataType : "json",
			async:true,  
			success : function(data, status) {
				if(data.code="ok"){
					alert("审核表请求成功");
					var arr = data.message.split(','); // 分割参数
					window.open("/highschool/"+arr[0]);
					//window.open("/highschool/"+arr[1]);
				}
			},
			error : function (data) {
				alert("审核表打印失败:"+data.mesage);
				//window.open("/highschool/testV1.0.pdf");
				}
		})
		
	}
	function showPdf2(){

		PDFJS.workerSrc = 'js/pdf.worker.js';//加载核心库
		PDFJS.getDocument(url).then(function getPdfHelloWorld(pdf) {
		//
		// 获取第一页数据
		//
		pdf.getPage(1).then(function getPageHelloWorld(page) {
		var scale = 1.5;
		var viewport = page.getViewport(scale);

		//
		// Prepare canvas using PDF page dimensions
		//
		var canvas = document.getElementById('the-canvas');
		var context = canvas.getContext('2d');
		canvas.height = viewport.height;
		canvas.width = viewport.width;

		//
		// Render PDF page into canvas context
		//
		var renderContext = {
		canvasContext: context,
		viewport: viewport
		};
		page.render(renderContext);
		});
		});

		}
	
/*
	function PrintPdf() {

        if (document.getElementById("printIframe").attachEvent) {
             document.getElementById("printIframe").attachEvent("onload", function () { document.getElementById("printIframe").focus(); document.getElementById("printIframe").contentWindow.print(); });


         } else {
             document.getElementById("printIframe").onload = function () {
                 document.getElementById("printIframe").focus(); document.getElementById("printIframe").contentWindow.print();
             }
         }

         document.getElementById("printIframe").src = "testV1.0.pdf";

}
*/
	//打印考生资格审查表
	$(".printTablr33").on('click', function() {
		var row= $('#shenhetable').bootstrapTable('getSelections');
		if(row.length<1)
			{
			alert("未选择学生");
			return false ;
			}
		//var statu=0;
		//for (var index=0;index<row.length;index++){
			//var bmh=row[0].bmh;
			var DEFAULT_URL = "";//注意，删除的变量在这里重新定义  
            var PDFData = ""; 
				//执行审核请求
				$.ajax({
					type : 'GET',
					url : '/highschool/preview',
					//async: false,
					data : row[0],
					dataType : "json",
					async:false,  
				    mimeType: 'text/plain; charset=x-user-defined',

					complete : function  (XMLHttpRequest, textStatus){
				          var win = window.open("about:blank");
							  win.document.open("application/pdf","");
				              win.document.write(XMLHttpRequest.responseText);
				              win.document.close();
				      }, 

					success : function(data) {
						//statu++;
						PDFData = data.responseText;
					},
					error : function (data,XMLHttpRequest, textStatus) {
						alert(data);
						PDFData = data.responseText;
						alert("审核表打印失败");
						}
				})
				/*
			var rawLength = PDFData.length;  
			//转换成pdf.js能直接解析的Uint8Array类型,见pdf.js-4068  
			var array = new Uint8Array(new ArrayBuffer(rawLength));    
			for(i = 0; i < rawLength; i++) {  
			  array[i] = PDFData.charCodeAt(i) & 0xff;  
			}  
			DEFAULT_URL = array;
			 var win = window.open("about:blank");
			 win.document.open("application/pdf","_self");
          win.document.write(XMLHttpRequest.responseText);
          win.document.close();
          */
		//}
	})

	//全选
	$('.checkall').on(
			'change',
			function() {
				console.log($(this).is(':checked'))
				var checkstate = $(this).is(':checked');
				if (checkstate == true) {
					//全选
					$('tbody tr').find('input[type=checkbox].chose').prop(
							'checked', true);
				} else {
					//取消全选
					$('tbody tr').find('input[type=checkbox].chose').prop(
							'checked', false);
				}
			})

	//批量审核
	$('#shenghe').on('click',function() {
		var row= $('#shenhetable').bootstrapTable('getSelections');
		if(row.length<1)
			{
			alert("未选择学生");
			return false ;
			}
		var statu=0;
		for (var index=0;index<row.length;index++){
			var bmh=row[index].bmh;
				//执行审核请求
				$.ajax({
					type : 'POST',
					url : 'doExamineYt',
					async: false,
					data : {
						'bmh':bmh
					},//获取表单数据，select的name属性你自己加一下吧
					dataType : "json",
					success : function(data) {
						statu++;
					},
					error : function () {alert("审核失败")}
				})
		}
		$("#shenhetable").bootstrapTable('refresh',{url:"showHighSchoolYt"});
	})
	
	//批量清除审核
	$(".schoolgoshenghe").on('click',function() {
		var row= $('#shenhetable').bootstrapTable('getSelections');
		if(row.length<1)
		{
		alert("未选择学生");
		return false ;
		}
		var statu=0;
		for (var index=0;index<row.length;index++){
			var bmh=row[index].bmh;
				//执行审核请求
				$.ajax({
					type : 'POST',
					url : 'doCancelExamineYt',
					async: false,
					data : {
						'bmh':bmh
					},//获取表单数据，select的name属性你自己加一下吧
					dataType : "json",
					success : function(data) {
						{ statu=statu+1;}
					},
					error : function () {alert("取消失败")
				    }
				})
		};
		if (statu>0){alert("清除成功")};
		$("#shenhetable").bootstrapTable('refresh',{url:"showHighSchoolYt"});
	})
			
	$('tbody tr').dblclick(
			function() {
				var _this = this;
				$(_this).find('input[type=checkbox]').attr('disabled', false)
						.addClass('edt');
			})

	//点击录入成绩
	$(".insertchengji").on('click', function() {
alert("test");
	})
</script>
<script src="js/viewer.js"></script>
</html>